<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 委托单
 */
class Entrust extends Model
{
    protected $table = 'entrust';

    protected $fillable = [
        'id',
        'uid', //用户id
        'cid', //货币id
        'number_no', //编号
        'type', //类型 1买入 2卖出
        'price', //价格
        'num', //挂单数量
        'deal', //成交数量
        'proc', //手续费
        'deal_time', //成交时间
        'created_at', //成交时间
        'status', //状态 1未成交 2 部分成交 3已成交 4部分撤销 5全部撤销
    ];

    const TYPE_ONE = 3;
    const TYPE_TWO = 4;
    public static $TYPE = [
        self::TYPE_ONE => '委托买入',
        self::TYPE_TWO => '委托卖出',
    ];

    const STATIC_A = 1;
    const STATIC_B = 2;
    const STATIC_C = 3;
    const STATIC_D = 4;
    const STATIC_E = 5;
    public static $STATUS = [
        self::STATIC_A => '未成交',
        self::STATIC_B => '部分成交',
        self::STATIC_C => '已成交',
        self::STATIC_D => '部分撤销',
        self::STATIC_E => '全部撤销',
    ];

    //关联用户表
    public function user()
    {
        return $this->hasOne('App\\Models\\User', 'id', 'uid');
    }
    //关联货币表
    public function currency()
    {
        return $this->hasOne('App\\Models\\Currency', 'id', 'cid');
    }
    //关联交易单
    public function orders()
    {
        return $this->hasMany('App\\Models\\Order', 'eid', 'id');
    }
}
